using FAQ_UI;
using java.io;
using java.lang;
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Media;
using System.Windows.Resources;
using NotImplementedException = System.NotImplementedException;

namespace Vec
{
	public class VECfile : Drawable
	{
		public static List<TypefaceMap> typefaceMap = new List<TypefaceMap>();
		protected WPFPaint paint = new WPFPaint();
		protected int width, height;//图像大小
		protected float dp;//精度
		protected List<Shape> shapes = new List<Shape>();
		protected bool antialias = true, dither = false;
		protected int backgcolor = 0;
		protected string name = "", info = "", bgpath = "";
		protected byte version = 3;
		private int alpha = 255;

		public VECfile(int width, int height, float dp, string b)
		{
			bgpath = b;
			this.width = width;
			this.height = height;
			this.dp = dp;
			bgpath = b;
		}

		public VECfile()
		{
		}

		public VECfile(VECfile src)
		{
			width = src.width;
			height = src.height;
			dp = src.dp;
			antialias = src.antialias;
			dither = src.dither;
			backgcolor = src.backgcolor;
			name = src.name;
			info = src.info;
			bgpath = src.bgpath;
			version = 3;
			foreach (Shape s in src.shapes)
				shapes.Add(new Shape(s));
		}

		public static void addTypefaceMap(int start, int end, Typeface type)
		{
			TypefaceMap t = new TypefaceMap();
			t.charSection[0] = start;
			t.charSection[1] = end;
			t.typeface = type;
			typefaceMap.Add(t);
		}

		/*public static Bitmap createBitmap(VECfile v, int w, int h)
        {
            return v.createBitmap(w, h);
        }
        public static Bitmap createBitmap(Context ctx, string assetPath, int width, int height)
        {
            VECfile vf = fromAssets(ctx, assetPath);
            if (vf == null) return null;
            return vf.createBitmap(width, height);
        }*/

		public static VECfile readFileFromIs(InputStream inp)
		{
			return fromInputStream(inp);
		}

		public static VECfile readFile(string path)
		{
			return fromFile(path);
		}

		public static VECfile readXmlFromIs(InputStream iss)
		{
			return fromXML(iss);
		}

		public static VECfile readXml(string path)
		{
			return fromXMLFile(path);
		}

		public static VECfile fromXMLFile(string file)
		{
			return fromXML(new FileInputStream(file));
		}

		public static VECfile fromFile(string file)
		{
			return fromInputStream(new FileInputStream(file));
		}

		public static VECfile fromInputStream(InputStream iss)
		{
			try
			{
				VECfile v = new VECfile();
				v.mRead(iss);
				return v;
			}
			catch (IOException e)
			{
				return null;
			}
		}

		public static VECfile fromXML(InputStream iss)
		{
			/*try
            {
                VECfile v = new VECfile();
                v.mReadXml(iss);
                return v;
            }
            catch (Exception e)
            {
                return null;
            }*/
			throw new NotImplementedException();
		}

		/* public static VECfile fromXML(string xml)
         {
             return fromXML(new ByteArrayInputStream(xml.getBytes()));
         }*/
		/*public static VECfile fromRes(Context ctx, int resId)
        {
            try
            {
                string pkgName = ctx.getResources().getResourcePackageName(resId);
                string name = ctx.getResources().getResourceEntryName(resId);
                string apk = ctx.getPackageManager().getPackageInfo(pkgName, PackageManager.GET_ACTIVITIES).applicationInfo.publicSourceDir;
                ZipFile f = new ZipFile(apk);
                ZipEntry en = f.getEntry("res/drawable/" + name + ".png");
                InputStream i = f.getInputStream(en);
                return fromInputStream(i);
            }
            catch (Exception e)
            {
                return null;
            }
        }*/

		public static VECfile fromAssets(string assetsPath)
		{
			try
			{
				StreamResourceInfo info = Application.GetResourceStream(new Uri(assetsPath, UriKind.Relative));
				return fromInputStream(info.Stream);
			}
			catch (IOException e)
			{
				return null;
			}
		}

		private static VECfile fromInputStream(System.IO.Stream stream)
		{
			byte[] b = new byte[1024];
			int i;
			ByteArrayOutputStream bao = new ByteArrayOutputStream();
			while ((i = stream.Read(b, 0, b.Length)) != 0)
			{
				bao.write(b, 0, i);
			}
			stream.Close();
			return fromInputStream(new ByteArrayInputStream(bao.toByteArray()));
		}

		/*public Bitmap createBitmap(int width, int height)
        {
            Bitmap b = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
            Canvas can = new Canvas(b);
            can.drawColor(backgcolor);
            setBounds(0, 0, width, height);
            draw(can);
            return b;
        }*/

		public int getIntrinsicWidth()
		{
			return -1;
		}

		public int getIntrinsicHeight()
		{
			return -1;
		}

		public void setTheme(int color)
		{
			foreach (Shape s in shapes)
			{
				s.setColor(color);
				s.setStrokeColor(color);
			}
			invalidateSelf();
		}

		public override void draw(DrawingContext pp1)
		{
			WPFCanvas p1 = new WPFCanvas(pp1);
			paint.reset();
			paint.setAntiAlias(antialias);
			paint.setDither(dither);
			Rect b = new Rect((int)bounds.X, (int)bounds.Y, (int)bounds.Right, (int)bounds.Bottom);
			int i = p1.saveLayer(b.left, b.top, b.right, b.bottom, paint, WPFCanvas.ALL_SAVE_FLAG);
			p1.clipRect(b);
			float xscale = (float)b.width() / (float)width, yscale = (float)b.height() / (float)height;
			p1.drawColor(backgcolor);
			foreach (Shape s in shapes)
				s.draw(p1, b.left, b.top, xscale, yscale, alpha, dp, paint);
			p1.restoreToCount(i);
		}

		private void mRead(InputStream inp)
		{
			DataInputStream os = new DataInputStream(inp);
			byte[] h = new byte[4];
			os.read(h);
			if (h[0] != 'V' || h[1] != 'E' || h[2] != 'C') throw new IllegalStateException("不是标准的vec文件");
			else if (h[3] == 1)
			{
				readV1(os);
			}
			else if (h[3] == 2)
			{
				readV2(os);
			}
			else if (h[3] == version)
			{
				name = os.readUTF();
				info = os.readUTF();
				width = os.readInt();
				height = os.readInt();
				antialias = os.readBoolean();
				dither = os.readBoolean();
				backgcolor = os.readInt();
				dp = os.readFloat();
				shapes.Clear();
				int siz = os.readInt();
				for (int i = 0; i < siz; i++)
				{
					Shape s = new Shape(0);
					s.flag = os.readLong();
					if (s.hasFlag(Shape.TYPE.TEXT)) s.txt = os.readUTF();
					int ptsl = os.readInt();
					s.pts.Clear();
					if (s.hasFlag(Shape.TYPE.PATH))
						for (int u = 0; u < ptsl; u++)
						{
							Shape.PathPoint po = new Shape.PathPoint();
							po.x = os.readInt();
							po.y = os.readInt();
							if (u != 0) po.type = os.readByte();
							s.pts.Add(po);
						}
					else
						for (int u = 0; u < ptsl; u++)
						{
							Point po = new Point();
							po.x = os.readInt();
							po.y = os.readInt();
							s.pts.Add(po);
						}
					for (int u = 0; u < 12; u++) s.par[u] = os.readInt();
					s.dashPattern = os.readUTF();
					int li = os.readInt(), ra = os.readInt(), sw = os.readInt();
					for (int u = 0; u < li; u++)
					{
						Point po = new Point();
						po.x = os.readInt();
						po.y = os.readInt();
						s.linear.Add(po);
					}
					for (int u = 0; u < ra; u++)
					{
						Point po = new Point();
						po.x = os.readInt();
						po.y = os.readInt();
						s.radial.Add(po);
					}
					for (int u = 0; u < sw; u++)
					{
						Point po = new Point();
						po.x = os.readInt();
						po.y = os.readInt();
						s.sweep.Add(po);
					}
					shapes.Add(s);
				}
				if (os.available() > 0) bgpath = os.readUTF();
				os.close();
			}
			else throw new IllegalStateException("不支持的vec文件");
		}

		private void readV2(DataInputStream os)
		{
			version = 2;
			name = os.readUTF();
			info = os.readUTF();
			width = os.readInt();
			height = os.readInt();
			antialias = os.readBoolean();
			dither = os.readBoolean();
			backgcolor = os.readInt();
			dp = os.readFloat();
			shapes.Clear();
			int siz = os.readInt();
			for (int i = 0; i < siz; i++)
			{
				Shape s = new Shape(0);
				s.flag = os.readLong();
				if (s.hasFlag(Shape.TYPE.TEXT)) s.txt = os.readUTF();
				int ptsl = os.readInt();
				s.pts.Clear();
				if (s.hasFlag(Shape.TYPE.PATH))
					for (int u = 0; u < ptsl; u++)
					{
						Shape.PathPoint po = new Shape.PathPoint();
						po.x = os.readInt();
						po.y = os.readInt();
						if (u != 0) po.type = os.readByte();
						s.pts.Add(po);
					}
				else
					for (int u = 0; u < ptsl; u++)
					{
						Point po = new Point();
						po.x = os.readInt();
						po.y = os.readInt();
						s.pts.Add(po);
					}
				for (int u = 0; u < 8; u++) s.par[u] = os.readInt();
				int li = os.readInt(), ra = os.readInt(), sw = os.readInt();
				for (int u = 0; u < li; u++)
				{
					Point po = new Point();
					po.x = os.readInt();
					po.y = os.readInt();
					s.linear.Add(po);
				}
				for (int u = 0; u < ra; u++)
				{
					Point po = new Point();
					po.x = os.readInt();
					po.y = os.readInt();
					s.radial.Add(po);
				}
				for (int u = 0; u < sw; u++)
				{
					Point po = new Point();
					po.x = os.readInt();
					po.y = os.readInt();
					s.sweep.Add(po);
				}
				shapes.Add(s);
			}
			if (os.available() > 0) bgpath = os.readUTF();
			os.close();
		}

		private void readV1(DataInputStream os)
		{
			version = 1;
			name = os.readUTF();
			info = os.readUTF();
			width = os.readInt();
			height = os.readInt();
			antialias = os.readBoolean();
			dither = os.readBoolean();
			backgcolor = os.readInt();
			dp = os.readFloat();
			shapes.Clear();
			int siz = os.readInt();
			for (int i = 0; i < siz; i++)
			{
				Shape s = new Shape(0);
				s.flag = os.readLong();
				if (s.hasFlag(Shape.TYPE.TEXT)) s.txt = os.readUTF();
				int ptsl = os.readInt();
				s.pts.Clear();
				if (s.hasFlag(Shape.TYPE.PATH))
					for (int u = 0; u < ptsl; u++)
					{
						Shape.PathPoint po = new Shape.PathPoint();
						po.x = os.readInt();
						po.y = os.readInt();
						if (u != 0) po.type = os.readByte();
						s.pts.Add(po);
					}
				else
					for (int u = 0; u < ptsl; u++)
					{
						Point po = new Point();
						po.x = os.readInt();
						po.y = os.readInt();
						s.pts.Add(po);
					}
				for (int u = 0; u < 8; u++) s.par[u] = os.readInt();
				shapes.Add(s);
			}
			if (os.available() > 0) bgpath = os.readUTF();
			os.close();
		}

		/*private void mReadXml(InputStream iss)
        {
            SAXParserFactory sf = SAXParserFactory.newInstance();
            SAXParser sp = sf.newSAXParser();
            DefaultHandler reader = new DefaultHandler(){
            Shape tmp=null;
            public void startElement(string uri, string localName, string qName, Attributes a)
            {
                if (a.getLength() >= 0)
                {
                    switch (qName)
                    {
                        case "VEC":
                            version = Byte.parseByte(a.getValue("version"));
                            //if("VEC")throw new IllegalStateException("不支持的vec文件");
                            break;

                        case "Data":
                            name = a.getValue("name");
                            info = a.getValue("info");
                            width = Integer.parseInt(a.getValue("width"));
                            height = Integer.parseInt(a.getValue("height"));
                            antialias = Boolean.parseBoolean(a.getValue("antialias"));
                            dither = Boolean.parseBoolean(a.getValue("dither"));
                            backgcolor = new BigInteger(a.getValue("backgroundColor"), 16).intValue();
                            dp = Float.parseFloat(a.getValue("dp"));
                            break;

                        case "BackgroundImg":
                            string p = a.getValue("path");
                            if (!"null".equals(p)) bgpath = p;
                            break;

                        case "Shape":
                            tmp = new Shape(0);
                            tmp.flag = Long.parseLong(a.getValue("flag"), 2);
                            if (tmp.hasFlag(Shape.TYPE.TEXT)) tmp.txt = a.getValue("text");
                            break;

                        case "Points":
                            tmp.pts.Clear();
                            break;

                        case "P":
                            if (tmp.hasFlag(Shape.TYPE.PATH))
                            {
                                Shape.PathPoint po = new Shape.PathPoint();
                                po.x = Integer.parseInt(a.getValue("x"));
                                po.y = Integer.parseInt(a.getValue("y"));
                                string h = a.getValue("t");
                                if (h != null) po.type = Byte.parseByte(h);
                                tmp.pts.Add(po);
                            }
                            else
                            {
                                Point po = new Point();
                                po.x = Integer.parseInt(a.getValue("x"));
                                po.y = Integer.parseInt(a.getValue("y"));
                                tmp.pts.Add(po);
                            }
                            break;

                        case "Params":
                            for (int u = 0; u < 12 && a.getValue("p" + u) != null; u++)
                                tmp.par[u] = u == 0 || u == 1 || u == 7 ? new BigInteger(a.getValue("p" + u), 16).intValue() : Integer.parseInt(a.getValue("p" + u));
                            break;

                        case "Linear":
                            Point po = new Point();
                            po.x = tmp.linear.Count >= 2 ? new BigInteger(a.getValue("x"), 16).intValue() : Integer.parseInt(a.getValue("x"));
                            po.y = Integer.parseInt(a.getValue("y"));
                            tmp.linear.Add(po);
                            break;

                        case "Radial":
                            po = new Point();
                            po.x = tmp.radial.Count >= 2 ? new BigInteger(a.getValue("x"), 16).intValue() : Integer.parseInt(a.getValue("x"));
                            po.y = Integer.parseInt(a.getValue("y"));
                            tmp.radial.Add(po);
                            break;

                        case "Sweep":
                            po = new Point();
                            po.x = tmp.sweep.Count >= 1 ? new BigInteger(a.getValue("x"), 16).intValue() : Integer.parseInt(a.getValue("x"));
                            po.y = Integer.parseInt(a.getValue("y"));
                            tmp.sweep.Add(po);
                            break;

                        case "Dash":
                            string x = a.getValue("arr");
                            tmp.dashPattern = x == null ? "" : x;
                            break;

                        default:
                            break;
                    }
                }
            }
            public void endElement(string uri, string localName, string qName)
            {
                if ("Shape".equals(qName))
                {
                    addShape(tmp);
                    tmp = null;
                }
            }
        };
        sp.parse(iss, reader);
		iss.close();
	}*/

		public int getWidth()
		{
			return width;
		}

		public void setWidth(int width)
		{
			this.width = width;
		}

		public int getHeight()
		{
			return height;
		}

		public void setHeight(int height)
		{
			this.height = height;
		}

		public float getDp()
		{
			return dp;
		}

		public void setDp(float dp)
		{
			this.dp = dp;
		}

		public int getBackgcolor()
		{
			return backgcolor;
		}

		public void setBackgcolor(int backgcolor)
		{
			this.backgcolor = backgcolor;
		}

		public List<Shape> getShapes()
		{
			return shapes;
		}

		public void setShapes(List<Shape> shapes)
		{
			this.shapes.Clear();
			this.shapes.AddRange(shapes);
		}

		public string getName()
		{
			return name;
		}

		public void setName(string name)
		{
			this.name = name;
		}

		public string getInfo()
		{
			return info;
		}

		public void setInfo(string info)
		{
			this.info = info;
		}

		public string getBgpath()
		{
			return bgpath;
		}

		public void setBgpath(string bgpath)
		{
			this.bgpath = bgpath;
		}

		public bool isAntialias()
		{
			return antialias;
		}

		public void setAntialias(bool antialias)
		{
			this.antialias = antialias;
		}

		public bool isDither()
		{
			return dither;
		}

		public void setDither(bool dither)
		{
			this.dither = dither;
		}

		/*public void loadoutTxtFile(string f)
        {
            toText(new FileOutputStream(f));
        }
        public string toText()
        {
            try
            {
                ByteArrayOutputStream b = new ByteArrayOutputStream();
                toText(b);
                b.flush();
                b.close();
                return b.toString();
            }
            catch (Throwable e)
            {
                return null;
            }
        }*/
		/*public void toText(OutputStream out)
        {
            synchronized(shapes){
                PrintWriter os = new PrintWriter(out);
                os.println("VEC 版本:1");
                os.println("文件名:" + name + ";描述:" + info);
                os.println("宽:" + width + ";高:" + height + ";精度:" + (int)(width / dp));
                os.println("抗锯齿:" + antialias + ";防抖动:" + dither);
                os.println("背景色:" + Integer.toHexString(backgcolor));
                os.println("图形个数:" + shapes.Count);
                os.println("");
                foreach(Shape s in  shapes)
                {
                    os.println("标识:" + getFlagName(s));
                    if (s.hasFlag(Shape.TYPE.TEXT)) os.println("图形文字:" + s.txt);
                    os.println("点个数:" + s.pts.Count);
                    bool boole= false;
                    if (s.hasFlag(Shape.TYPE.PATH))
                        foreach(Point po in  s.pts)
                        {
                            if (boole)
                            {
                                int type = ((Shape.PathPoint)po).type;
                                string[] k = new string[] { "普通点", "拐点", "起点" };
                                os.println(po.x + "  " + po.y + "  type:" + k[type == 9 ? 0 : type]);
                            }
                            else os.println(po.x + "  " + po.y);
                            boole= true;
                        }
                    else
                        foreach(Point po in  s.pts)
                        {
                            os.println(po.x + "  " + po.y);
                        }
                    string[] k = new string[] { "颜色", "描线颜色", "锐角", "描线粗细", "阴影偏移x", "阴影偏移y", "阴影半径", "阴影颜色", "", "", "", "", "", "", "", "" };
                    for (int i = 0; i < s.par.Length; i++)
                    {
                        if (i == 0 || i == 1 || i == 7) os.println(k[i] + ":" + Integer.toHexString((int)s.par[i]));
                        else os.println(k[i] + ":" + s.par[i]);
                    }
                    os.println("");
                }
                os.println("背景图片目录:" + bgpath);
                os.flush();
                os.close();
            }
        }*/
		/*private string getFlagName(Shape s)
        {
            stringBuilder b = new stringBuilder();
            string[] t = Long.toBinarystring(s.flag).split("");
            string[] n = new string[]{
                "左对齐","居中","右对齐","默认","粗体",
                "MONOSPACE","SANS_SERIF","SERIF",
                "无线帽","圆帽","方帽","圆拐角","锐角",
                "直线","填充","描线","填充描线","描线填充",
                "CLEAR",
                "DARKEN",
                "DST",
                "DST_ATOP",
                "DST_IN",
                "DST_OUT",
                "DST_OVER",
                "LIGHTEN",
                "MULTIPLY",
                "OVERLAY",
                "SCREEN",
                "SRC",
                "SRC_ATOP",
                "SRC_IN",
                "SRC_OUT",
                "SRC_OVER",
                "XOR",
                "ADD",
                "新图层","回图层","中心","封闭","扫描",
                "辐射","线性","虚线","离散","圆角","组合",
                "矩形","圆形","椭圆","弧","圆角矩形","路径",
                "点","直线","文本"};
            for (int i = t.Length - 1; i >= 0; i--)
                if ("1"==(t[i]))
                {
                    b.append(n[t.Length - i - 1]);
                    b.append(" ");
                }
            return b.toString();
        }*/

		public void addShape(Shape s)
		{
			if (s != null) shapes.Add(s);
		}

		/* public void loadoutFile(string f)
         {
             try
             {
                 Bitmap bit = createBitmap(width, height);
                 BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(f));
                 bit.compress(Bitmap.CompressFormat.PNG, 100, os);
                 os.flush();
                 os.close();
                 bit.recycle();
             }
             catch (Exception ignored)
             {
             }
         }*/

		public void saveFile(string path)
		{
			writeToStream(new FileOutputStream(path));
		}

		public void writeToStream(OutputStream outt)
		{
			DataOutputStream os = new DataOutputStream(outt);
			os.writeBytes("VEC");
			os.writeByte(3);
			if (name != null) os.writeUTF(name);
			if (info != null) os.writeUTF(info);
			os.writeInt(width);
			os.writeInt(height);
			os.writeBoolean(antialias);
			os.writeBoolean(dither);
			os.writeInt(backgcolor);
			os.writeFloat(dp);
			os.writeInt(shapes.Count);
			foreach (Shape s in shapes)
			{
				os.writeLong(s.flag);
				if (s.hasFlag(Shape.TYPE.TEXT)) os.writeUTF(s.txt);
				os.writeInt(s.pts.Count);
				bool boole = false;
				if (s.hasFlag(Shape.TYPE.PATH))
					foreach (Point po in s.pts)
					{
						os.writeInt(po.x);
						os.writeInt(po.y);
						if (boole) os.writeByte(((Shape.PathPoint)po).type);
						boole = true;
					}
				else
					foreach (Point po in s.pts)
					{
						os.writeInt(po.x);
						os.writeInt(po.y);
					}
				foreach (int po in s.par) os.writeInt(po);
				os.writeUTF(s.dashPattern);
				os.writeInt(s.linear.Count);
				os.writeInt(s.radial.Count);
				os.writeInt(s.sweep.Count);
				foreach (Point t in s.linear)
				{
					os.writeInt(t.x);
					os.writeInt(t.y);
				}
				foreach (Point t in s.radial)
				{
					os.writeInt(t.x);
					os.writeInt(t.y);
				}
				foreach (Point t in s.sweep)
				{
					os.writeInt(t.x);
					os.writeInt(t.y);
				}
			}
			if (bgpath != null) os.writeUTF(bgpath);
			os.flush();
			os.close();
		}

		/*public void saveXML(string path)
        {
            FileOutputStream ba = new FileOutputStream(path);
            toXML(ba);
            ba.flush();
            ba.close();
        }*/
		/*public string toXML()
        {
            try
            {
                ByteArrayOutputStream ba = new ByteArrayOutputStream();
                toXML(ba);
                ba.flush();
                ba.close();
                return ba.toString();
            }
            catch (Exception e)
            {
                return null;
            }
        }*/
		/*public void toXML(OutputStream os)
        {
            synchronized(shapes){
                SAXTransformerFactory sf = (SAXTransformerFactory)SAXTransformerFactory.newInstance();
                TransformerHandler handler = sf.newTransformerHandler();
                Transformer transformer = handler.getTransformer();
                transformer.setOutputProperty(OutputKeys.STANDALONE, "yes");
                transformer.setOutputProperty(OutputKeys.ENCODING, "utf-8");
                transformer.setOutputProperty(OutputKeys.INDENT, "yes");
                Result result = new StreamResult(os);
                handler.setResult(result);
                handler.startDocument();
                AttributesImpl a = new AttributesImpl();
                a.addAttribute("", "", "version", "", "" + version);
                handler.startElement("", "", "VEC", a);
                a.Clear();
                a.addAttribute("", "", "name", "", name);
                a.addAttribute("", "", "info", "", info);
                a.addAttribute("", "", "width", "", Integer.toString(width));
                a.addAttribute("", "", "height", "", Integer.toString(height));
                a.addAttribute("", "", "antialias", "", Boolean.toString(antialias));
                a.addAttribute("", "", "dither", "", Boolean.toString(dither));
                a.addAttribute("", "", "backgroundColor", "", Integer.toHexString(backgcolor));
                a.addAttribute("", "", "dp", "", Float.toString(dp));
                handler.startElement("", "", "Data", a);
                handler.endElement("", "", "Data");
                a.Clear();
                a.addAttribute("", "", "path", "", bgpath == null ? "null" : bgpath);
                handler.startElement("", "", "BackgroundImg", a);
                handler.endElement("", "", "BackgroundImg");
                a.Clear();
                foreach(Shape s in  shapes)
                {
                    a.addAttribute("", "", "flag", "", Long.toBinarystring(s.flag));
                    if (s.hasFlag(Shape.TYPE.TEXT)) a.addAttribute("", "", "text", "", s.txt);
                    handler.startElement("", "", "Shape", a);
                    a.Clear();
                    handler.startElement("", "", "Points", a);
                    bool bool= false;
                    if (s.hasFlag(Shape.TYPE.PATH))
                        foreach(Point po in  s.pts)
                        {
                            a.addAttribute("", "", "x", "", Integer.toString(po.x));
                            a.addAttribute("", "", "y", "", Integer.toString(po.y));
                            if (bool)
                                a.addAttribute("", "", "t", "", Integer.toString(((Shape.PathPoint)po).type));
                            handler.startElement("", "", "P", a);
                            handler.endElement("", "", "P");
                            a.Clear();
                            bool= true;
                        }
                    else
                        foreach(Point po in  s.pts)
                        {
                            a.addAttribute("", "", "x", "", Integer.toString(po.x));
                            a.addAttribute("", "", "y", "", Integer.toString(po.y));
                            handler.startElement("", "", "P", a);
                            handler.endElement("", "", "P");
                            a.Clear();
                        }
                    handler.endElement("", "", "Points");
                    int f = -1;
                    foreach (int po in s.par)
                        a.addAttribute("", "", "p" + (++f), "", f == 0 || f == 1 || f == 7 ? Integer.toHexString(po) : Integer.toString(po));
                    handler.startElement("", "", "Params", a);
                    handler.endElement("", "", "Params");
                    a.Clear();
                    a.addAttribute("", "", "arr", "", s.dashPattern);
                    handler.startElement("", "", "Dash", a);
                    handler.endElement("", "", "Dash");
                    a.Clear();
                    handler.startElement("", "", "Shader", a);
                    f = 0;
                    foreach (Point t in s.linear)
                    {
                        if (f < 2) a.addAttribute("", "", "x", "", Integer.toString(t.x));
                        else a.addAttribute("", "", "x", "", Integer.toHexString(t.x));
                        a.addAttribute("", "", "y", "", Integer.toString(t.y));
                        handler.startElement("", "", "Linear", a);
                        handler.endElement("", "", "Linear");
                        a.Clear();
                        f++;
                    }
                    f = 0;
                    foreach (Point t in s.radial)
                    {
                        if (f < 2) a.addAttribute("", "", "x", "", Integer.toString(t.x));
                        else a.addAttribute("", "", "x", "", Integer.toHexString(t.x));
                        a.addAttribute("", "", "y", "", Integer.toString(t.y));
                        handler.startElement("", "", "Radial", a);
                        handler.endElement("", "", "Radial");
                        a.Clear();
                        f++;
                    }
                    f = 0;
                    foreach (Point t in s.sweep)
                    {
                        if (f < 1) a.addAttribute("", "", "x", "", Integer.toString(t.x));
                        else a.addAttribute("", "", "x", "", Integer.toHexString(t.x));
                        a.addAttribute("", "", "y", "", Integer.toString(t.y));
                        handler.startElement("", "", "Sweep", a);
                        handler.endElement("", "", "Sweep");
                        a.Clear();
                        f++;
                    }
                    handler.endElement("", "", "Shader");
                    handler.endElement("", "", "Shape");
                }
                handler.endElement("", "", "VEC");
                handler.endDocument();
            }
        }
    */

		public void setAlpha(int p1)
		{
			alpha = p1;
		}

		public Drawable mutate()
		{
			return new VECfile(this);
		}

		public class TypefaceMap
		{
			public int[] charSection = new int[2];
			public object typeface;
		}

		public class Builder
		{
			private int width = 500, height = 500;//图像大小
			private float dp = 20;//精度
			private int backgcolor = 0;
			private string name = "未命名", comm = "请输入描述", bgpath = null;
			private bool antialias = true, dither = false;

			public int getWidth()
			{
				return width;
			}

			public void setWidth(int width)
			{
				this.width = width;
			}

			public int getHeight()
			{
				return height;
			}

			public void setHeight(int height)
			{
				this.height = height;
			}

			public float getDp()
			{
				return dp;
			}

			public void setDp(float dp)
			{
				this.dp = dp;
			}

			public int getBackgcolor()
			{
				return backgcolor;
			}

			public void setBackgcolor(int backgcolor)
			{
				this.backgcolor = backgcolor;
			}

			public string getName()
			{
				return name;
			}

			public void setName(string name)
			{
				this.name = name;
			}

			public string getComm()
			{
				return comm;
			}

			public void setComm(string comm)
			{
				this.comm = comm;
			}

			public string getBgpath()
			{
				return bgpath;
			}

			public void setBgpath(string bgpath)
			{
				this.bgpath = bgpath;
			}

			public bool isAntialias()
			{
				return antialias;
			}

			public void setAntialias(bool antialias)
			{
				this.antialias = antialias;
			}

			public bool isDither()
			{
				return dither;
			}

			public void setDither(bool dither)
			{
				this.dither = dither;
			}

			public VECfile build()
			{
				VECfile v = new VECfile(this.width, this.height, this.dp, this.bgpath);
				v.backgcolor = this.backgcolor;
				v.name = this.name;
				v.info = this.comm;
				v.antialias = this.antialias = false;
				v.dither = this.dither;
				return v;
			}
		}
	}
}